II Something
by Clark Hugh Stiles
December 12, 2001 

I've managed to do one of these a week, although the previous two were a little late. This one is on time, which is saying something considering that it's a busy time of the year. Before I forget, I hope you have a happy bunch of holidays. 

Open-Apple, July 1986, (in the bound version, Vol 2, page 2.47) has three solutions for starting up the 80 column card from ML. The method I'd made up myself worked fine, but blew off Basic.System, and warmstarting it with a JSR just dumped me onto the bracket prompt, ending the ML program. In other words, it didn't work fine. 

The first method is for programs which are not coresident with Basic.System, which this block editor program will be, but all three methods start the same way. There's a 15 byte example in the little article, but Listing 1 below uses the other suggested method. 

Step one is to check the MACHID byte ($BF98, byte 1, of 7-0) to see if there is an 80-column card. Step two is copy the string PR#3 to the input buffer at $200. Step three is to call DOSCMD ($BE03). Step four is to check to see if the carry is set, because if it is there was an error the ML program will have to handle. 

Listing 1: 
CALL-151
*!
300:LDX #$00
LDY #$14
LDA 300,Y
BEQ 313
STA 200,X
INX
INY
BNE 0304
JSR BE03
RTS
![return]
*314:"PR#3"
*318:0D 00
*300.319
0300:A2 00 A0 14 B9 00 03 F0 0A 9D 00 02 E8 C8 D0 F4-". .9..p....hHPt
0310:20 03 BE 60 D0 D2 A3 B3 0D 00- .>`PR#3.. 
End of Program Listing. 

This stores the PR#3 string after the RTS (return to sender) and ends the string with a zero to simplify things. The problem I had with this great routine is that it didn't work. I'm sure some real programmer will stop in soon and show me the lunkhead error I've made, or to tell me that it works fine, but not under Bernie. So, I'll be rippin' off the 15 byte example mentioned earlier. We'll add the test for the existence of the 80 columns, all the while keeping in mind that this technique works under ProDOS and Basic.System only. 

Listing 2: 
CALL-151
*!
0300:LDA BF98
ROR
ROR
BCC 0316
LDA #00
STA BE30
LDA #C3
STA BE31
LDA #99
JSR FDED
RTS
*BSAVE OA2.47PR3,A$300,L$17
![return]
*[control-c,return] 
End of Program Listing. 

From non-80 column mode, CALL 768 to turn on 80 columns, unless there's no 80 column card, in which case nothing much will happen. If you're already in 80 columns you know the answer, but want to test it, so from Applesoft PRINT CHR$(21) and then CALL 768. CHR$(21) is Control-U which turns off 80 columns. This routine, or something very like it, will be at the very beginning of the finished program. I'd like to clear the screen, a la the Applesoft HOME command, but that shouldn't be difficult, even if I have to use the brute force method (printing 2000 spaces). 

The program loads A with the MACHID value, rolls the bits right until bit one is in the Carry flag, and if Carry is Clear (zero) knows that there is no 80 column card that ProDOS recognizes, and exits. If Carry is Set, it falls through and does its thing. In the finished program, the Carry may be Cleared just before the first LDA. 

To be elegant (and more useful in the finished block editor), instead of branching to the RTS the routine could load an appropriate number into the Accumulator (3, for "NO DEVICE CONNECTED"?), Set the Carry, and JMP to the error print routine in Basic.System. 

This was a lazy installment of II Something but one of the more useful ones beyond the context of this block editor project. It's nice to know that there is an easy, reliable way of starting up 80 columns from machine language that I actually could find around here (obviously there must be one, or there'd be NO 80 column using programs). 

II Infinitum! 